package lc_2597_美丽子集的数目;

public class Solution {
	public int beautifulSubsets(int[] nums, int k) {
		int n = nums.length;
		int[] e = new int[n];// 对于第i个数，前面哪些位置上的数不可用
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				if (Math.abs(nums[i] - nums[j]) == k) {
					e[i] |= 1 << j;
				}
			}
		}
		int[] dp = new int[1 << n];
		dp[0] = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 1 << i; j++) {
				if ((e[i] & j) == 0) {
					dp[j | 1 << i] = dp[j];
					ans += dp[j];
				}
			}
		}
		return ans;
	}
}
